let { projectRootPath } = require("../../../util/index");
let { getNewApp } = require(`${projectRootPath}/app/index.js`);
let { verifyToken } = require(`${projectRootPath}/util/jwt/index.js`);
let {
  uploadOwner,
  createOwner,
  getOwnerByPagination,
  getOwnerByPaginationAndQuestion,
  editOwnerByUuid,
  removeOwnerByUuid,
  getOwnerByAll,
} = require(`${projectRootPath}/service/owner/index.js`);
let app = getNewApp();

// 获取用户信息
app.post("/upload", async (req, res) => {
  try {
    let result = await uploadOwner(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 创建业主
app.post("/create", async (req, res) => {
  try {
    let result = await createOwner(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 获取业主分页数据
app.post("/get/pagination", async (req, res) => {
  try {
    let result = await getOwnerByPagination(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 获取业主分页数据并通过问题列表
app.post("/get/paginationAndQuestion", async (req, res) => {
  try {
    let result = await getOwnerByPaginationAndQuestion(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 通过 uuid 编辑业主
app.post("/edit/uuid", async (req, res) => {
  try {
    let result = await editOwnerByUuid(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 通过 uuid 删除业主
app.post("/remove/uuid", async (req, res) => {
  try {
    let result = await removeOwnerByUuid(req.body);
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
// 获取全部业主
app.post("/get/all", async (req, res) => {
  try {
    let result = await getOwnerByAll();
    res.send({ data: result, code: 20000 });
  } catch (error) {
    res.send({ data: {}, message: error.message, code: 20001 });
  }
});
module.exports = app;
